<meta charset="UTF-8">
<table
	     class="easyui-datagrid"   
	     id="datagrid"  
         title="会员管理"  
         url="${base}/user/list"
         toolbar="#searchtool,#toolbar" 
         pagination="true"
         rownumbers="true" 
         data-options="onClickCell:onClickCell,onEndEdit:onEndEdit,pageSize:20,pageList:[10,20,30]" >  
    <thead>  
        <tr>
            <th data-options="field:'uid',align:'center',checkbox:true" width="5%"></th>  
            <th data-options="field:'umobile',align:'center'" width="8%">手机号</th>  
            <th data-options="field:'ctime',align:'center'" width="10%">注册时间</th>
            <th data-options="field:'realname',align:'center'" width="10%">真实姓名</th>
            <th data-options="field:'govName',formatter:function(value,row,index){if(row.cityName){return value+'.'+row.cityName;}else{return value;}},align:'center'" width="10%">所在城市</th>
            <th data-options="field:'industry',align:'center'" width="7%">所属行业</th>     
            <th data-options="field:'org',align:'center'" width="15%">公司名称</th>     
            <th data-options="field:'position',align:'center'" width="10%">职务</th>     
            <th data-options="field:'status',align:'center',formatter:formatStatus" width="5%">会员状态</th>  
            <th width="20%" data-options="field:'depict',align:'center',editor:'textbox'">备注</th> 
            <th data-options="field:'_operate',width:60,align:'center',formatter:formatOper">操作</th> 
        </tr>
    </thead>
</table>  
<div id="searchtool" style="padding:5px">
  <form id="searchForm" method="post">
  <span>所属行业</span> <input class="easyui-combobox" id="industry" name="industry" data-options="valueField:'id',editable:true,textField:'industryName',url:'${base}/industry/queryAll',loadFilter:function(data){data.unshift({id:'',industryName:'所有'});return data;}" />
  <span>所在地区</span><input name="province" id="province" class="easyui-combobox" data-options="
                 url:'${base}/cityinfo/findAllProvince',
	 			 valueField:'postcode',
	 			 textField:'cityName',
	 			 panelHeight:200,
	 			 value:'0',
	 			 editable:false,
	 			 loadFilter:function(data){
    			    data.unshift({postcode:'0',cityName:'全国'});
    			    return data;
    		      },
	 			 onSelect: function(rec){
	 			  if(rec.postcode == '0'){ 
	 			       $('#city').combobox('setValue','');  
                       $('#city').combobox('disable');
                     }else{
	                    var url = '${base}/cityinfo/findCityProvince?code='+rec.postcode;
	                    $('#city').combobox('enable');
	                    $('#city').combobox('setValue','');    
	                    $('#city').combobox('reload', url); 
                      }
                     } " />&nbsp; <input name="city" id="city" class="easyui-combobox" data-options="valueField:'postcode',textField:'cityName',disabled:true" />
  <span>会员状态</span><select id="status" class="easyui-combobox" name="status" panelHeight="100" >   
				<option value=" ">全部</option> 
				<option value="3">已删除</option> 
				<option value="11">未回访</option>  
				<option value="12">已回访</option>   
               </select>  
  <span>起始时间</span><input name="startTime" id="startTime" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser" style="width:200px" >  
  <span>截止时间</span><input name="endTime" id="endTime" class="easyui-datebox"  data-options="formatter:myformatter,parser:myparser" style="width:200px" >  
  <span>关键字</span><input type="text" id="keyword" name="keyword" class="easyui-textbox" prompt="手机/公司/姓名" /> 
  <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="javascript:query('searchForm');">搜索</a>  
  <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="javascript:$('#searchForm').form('clear');">清空</a>
  </form>
</div>  
<div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:openUserEditDlg('编辑','user/edit','user-dlg','user-fm');">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="javascript:updateStatus('已回访',12);">已回访</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:updateStatus('删除',3);">删除</a>
</div> 
<div id="user-dlg" class="easyui-dialog"  style="padding:10px 20px" data-options="iconCls:'icon-save',closed:true,resizable:true,modal:true,buttons:'#userdlg-buttons'">
        <form id="user-fm" method="post">
            <div class="fitem">
                 <label>手机号:</label> <input class="easyui-textbox" name="umobile" id="umobile" required="true" validType="notemptyorblank"  readonly="true" />
            </div>
            <div class="fitem">
                 <label>行业:</label> <input name="industryId" id="industryId" />
            </div>
             <div class="fitem">
               <label>地区:</label> <input name="provinceId" id="provinceId" /> &nbsp; <input name="cityIds" id="cityIds" class="easyui-combobox" data-options="required:true,valueField:'postcode',textField:'cityName'" />
            </div>
             <div class="fitem">
                 <label>真实姓名:</label> <input class="easyui-textbox" name="realname" id="realname" required="true" validType="notemptyorblank" />
            </div>
            <div class="fitem">
                 <label>公司名称:</label> <input class="easyui-textbox" name="org" id="org" required="true" validType="notemptyorblank" />
            </div>
            <div class="fitem">
                 <label>职务:</label> <input class="easyui-textbox" name="position" id="position" required="true" validType="notemptyorblank" />
            </div>
            <div class="fitem">
                 <label>备注:</label> <input class="easyui-textbox" name="depict" id="depict"  validType="notemptyorblank" />
            </div>
        </form>
</div>
<div id="userdlg-buttons">
    <a href="javascript:void(0)" id="saveBtn" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="javascript:submit('user-dlg','user-fm');" style="width:90px">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#user-dlg').dialog('close')" style="width:90px">取消</a>
</div>
<div id="collectDiv" class="easyui-window"  style="padding:10px 20px" closed="true" modal="true">
</div>

<script type="text/javascript">
//状态:1-未激活,2-已锁定,3-已注销,11-正常但未认证，12-正常已认证
function formatStatus(val,row,index){
    if(val==1){
  	  return "未激活";
    }else if(val==2){
  	  return "已锁定"; 
    }else if(val==3){
		return '已删除';
	}else if(val==11){
		return '未回访';
	}else if(val==12){
		return '已回访';
	}else{
		return '未知';
	}
}

function query(formId) {
	var serializeObj = {};
	var array = $('#' + formId).serializeArray();
	$(array).each(
			function() {
				if (serializeObj[this.name]) {
					if ($.isArray(serializeObj[this.name])) {
						serializeObj[this.name].push(this.value);
					} else {
						serializeObj[this.name] = [serializeObj[this.name], this.value ];
					}
				} else {
					serializeObj[this.name] = this.value;
				}
			});
	queryData(serializeObj);
}


/* function authUser(){
	var rows = $('#datagrid').datagrid('getSelections');
	if (rows.length==1){
		if(rows[0].realname&&(rows[0].govId||rows[0].cityId)&&rows[0].industryId&&rows[0].org&&rows[0].infoValue){
			updateStatus('已回访',12);
		}else{
			$.messager.alert('提示',"已回访用户的真实姓名,地区,所属行业,公司名称,职务不能为空",'info');
	    }
	}else{
    	 $.messager.alert('提示','请选择一条信息进行操作','info');
    }
} */


function updateStatus(title,status){
	var rows = $('#datagrid').datagrid('getSelections');
    if (rows.length>0){
    	var ids = [];
    	for(var i=0; i<rows.length; i++){
    		ids.push(rows[i].uid);
    	}
    	url = $("#base").val()+"/user/updateStatus";
        $.messager.confirm(title,'确定'+title+'吗?',function(r){
            if (r){
                $.post(url,{'ids':ids.join(","),'status':status},function(result){
                	var result = jQuery.parseJSON(result);
                	if (result.success){
                 	   $.messager.alert('提示',result.msg,'info');
                 	   $('#datagrid').datagrid('reload');
                    }else {
                 	   $.messager.alert('错误',result.msg,'error');
                    }
                });
            }
        });
    }
}

function openUserEditDlg(title,actUrl,dlgId,fmId){
    var rows = $('#datagrid').datagrid('getSelections');
    if (rows&&rows.length==1){
    	$("#"+dlgId).dialog('open').dialog('setTitle',title);
    	$("#"+fmId).form('clear');
     	$('#industryId').combobox({
    		 url:'${base}/industry/queryAll',
    		 editable:false, //不可编辑状态  
    	     required:true,
    		 valueField:'id',
    		 textField:'industryName',
    		 loadFilter:function(data){
    			 data.shift();
    			 return data;
    		 }
    	});
    	 
     	$('#provinceId').combobox({
    		 url:'${base}/cityinfo/findAllProvince',
    		 valueField:'postcode',
    		 textField:'cityName',
    		 panelHeight:200,
    		 editable:false,
    		 onSelect: function(rec){
    	       var url = '${base}/cityinfo/findCityProvince?code='+rec.postcode;
    	       $('#cityIds').combobox('setValue','');
    	       $('#cityIds').combobox('reload', url);
    	  }
    	});
     	
        $("#provinceId").combobox("setValue", rows[0].govId);
        if(!isEmpty(rows[0].govId)){
	     	$('#cityIds').combobox('reload', '${base}/cityinfo/findCityProvince?code='+rows[0].govId);
	     	$('#cityIds').combobox("setValue", rows[0].cityId);
        }
    	$("#"+fmId).form('load',rows[0]);
        url = $("#base").val()+"/user/saveUser?uid="+rows[0].uid;
    }else{
    	$.messager.alert('提示','请选择一条数据进行操作','info');
    }

}

function onEndEdit(rowIndex, rowData, changes){
	if(!jQuery.isEmptyObject(new Object(changes))){
		$.post('${base}/user/saveUser',{'uid':rowData.uid,'depict':changes.depict},function(result){
			var result = jQuery.parseJSON(result);
	        if (result.success){
	     	   $.messager.alert('提示','更新数据成功','info');
	        }else{
	     	   $.messager.alert('错误','更新数据失败','error');
	        }
		});
	}
}


function formatOper(val,row,index){

	var showCollect = "<a href='javascript:showCollect(\""+row.uid+"\");'>查看收藏信息</a>";
    return showCollect;  
}

var $wins;
function showCollect(uid){
   var windowWidth =$(window.parent).width();
   var windowHeight=$(window.parent).height();
   var width= windowWidth-100;
   var height=windowHeight-200;
   var top=(windowHeight-height)/2;
   var left=(windowWidth-width)/2;
    $wins = $('#collectDiv').window({
    	href: 'userStatistic/showCollect?id='+uid+'&noCache=random',
        title: '显示收藏信息',
        width: width,
        height: height,
        top: top,
        left: left,
        shadow: true,
        modal: true,
        iconCls: 'icon-add',
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });
    $('#datagrid').datagrid('clearSelections');
    $wins.window('open');
}
</script>